import axios from 'axios';
import config from './config';

axios.defaults.baseURL = config.baseUrl;

//http拦截器
// Add a request interceptor
axios.interceptors.request.use(function (config) {
    // Do something before request is sent
    return config;
  }, function (err) {
    // Do something with request error
    alert("请求超时")
    return Promise.reject(err);
  });

// Add a response interceptor
axios.interceptors.response.use(function (response) {
    // Do something with response data
    return response;
  }, function (err) {
    // Do something with response error
    if (err.response.status >= 400 && err.response.status <= 500) {
        alert("错误码："+err.response.status+"----------错误信息："+err.response.data.message)
    }else if(err.response.status == 500){
      alert("错误码："+err.response.status+"----------错误信息："+err.response.data.message)
    }else{
      alert("错误码："+err.response.status+"----------错误信息："+err.response.data.message)
    }
    return Promise.reject(err);
  });

  export default axios;